#include <stdint.h>
#include "CLogcat.h"
#include "prc_ctrl.h"
//#include "nano_ble_direct.h"
#include "nano_remote_processor.h"
#include "jinju_remote_processor.h"

process_callback_p mPcb;

int init_pctrl(process_callback_p pcb) {
    LOGD("init_pctrl ");
    mPcb = pcb;
    return 0;
}

int start_pctrl(int id) {
    LOGD("start_pctrl : %d", id);
    int ret = 0;
    switch (id) {
        case NANO_HID:
        case NANO_BLE_NODE:
            ret = nano_rmt_init(mPcb, id);
            break;
        case JINJU_BLE_GATT:
            ret = jinju_rmt_init(mPcb);
            break;
        default:
            LOGW("start_pctrl : can not support this id:%d", id);
            ret = -1;
            break;
    }
    return ret;
}

int stop_pctrl(int id) {
    LOGD("stop_pctrl : %d", id);
    int ret = 0;
    switch (id) {
        case NANO_HID:
        case NANO_BLE_NODE:
            ret = nano_rmt_destroy();
            break;
        case JINJU_BLE_GATT:
            ret = jinju_rmt_destroy();
            break;
        default:
            LOGW("stop_pctrl : can not support this id:%d", id);
            ret = -1;
            break;
    }
    return ret;
}

int do_process(int id, unsigned char *data, int len) {
    int ret = 0;
    if (!mPcb) {
        return -1;
    }

    switch (id) {
        case NANO_HID:
            ret = nano_hid_process((char *) data, len);
            break;
//        case NANO_BLE_NODE:
        case JINJU_BLE_GATT:
            ret = jinju_rmt_process((char *) data, len);
            break;
        default:
            LOGW("do_process : can not support this id:%d", id);
            break;
    }

    return ret;
}

int destroy_pctrl() {
    LOGD("destroy_pctrl ");
    mPcb = NULL;
    return 0;
}

int get_device_state() {
    return nano_ble_deviceState();
}